from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
import uuid

GENDERS = (
    (0, '女'),
    (1, '男'),
    (2, '未知'),
)

# Create your models here.
class StudentProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    student_name = models.CharField(max_length=40, blank=True, null=True)
    student_id = models.CharField(max_length=20, unique=True)
    gender = models.IntegerField(default=2, choices=GENDERS)
    phone_number = models.CharField(max_length=15, blank=True, null=True)
    major = models.CharField(max_length=255, blank=True, null=True)
    enroll_year = models.CharField(max_length=4, blank=True, null=True)
    grade = models.CharField(max_length=4, blank=True, null=True) # 可能留级
    birthday = models.CharField(max_length=20, blank=True, null=True) # 可能留级
    classname = models.CharField(max_length=255, blank=True, null=True)
    height = models.FloatField(blank=True, null=True)
    weight = models.FloatField(blank=True, null=True)
    avatar = models.ImageField(upload_to='avatars/', blank=True, null=True)
    created = models.DateTimeField(auto_now_add=timezone.now)
    updated = models.DateTimeField(blank=True, null=True)

    def __str__(self):
        return f'<Student:{self.user.username}>'
